🛠tiny-bench
A tiny benchmarking library
The library
A benchmarking and timing library inspired by Criterion.
Inspired in this case means copying the things that criterion does well (and I do mean ctrl-c), like
statistical analysis of results, trimming that down, and leaving much of the customizability out.
Criterion is MIT licensed, please see the license at that repo or
here.
Primary goals
- Reliable results
- Fast build
- No dependencies
- Simple code that anyone can read, understand, and modify
Purpose
Sometimes you just need some back-of-the-envelope calculations of how long something takes. This library aims to fulfill that need and not much else.
The aim of the benchmarking is to be accurate enough to deliver reliable benchmarks with a minimal footprint, so that you can easily get a sense of whether you're going down a bad path.
The aim of the timing is to provide something that will let you figure out the same with the caveat of not being as reliable. It times some code so that you can get a sense of how much time pieces of your code takes to run.
Caveats
This library does not aim to provide production grade analysis tooling. It just prints data to stdout to guide you.
If you need advanced analysis Criterion has tooling better suited to that.
If you need to find where your application spends its time flamegraph
may be better suited for that.
If you need to track single pieces of your application when it's running Tracing
may be better suited for that.
Lastly, if you want an even smaller benchmarking library, check
out benchmark-simple.
Unimplemented
There are a few statistical measures that would be nice to have but are limited by the methods used by this library.
Since it potentially runs billions of iterations, calculating statistics based on seeing all iterations such as median,
standard deviation, and percentiles are not feasible without caching data to disk.
Therefore, measures like variance, or median are prefixed by "sample" as they are not related to individual iteration times,
but a comparison between samples.
There is no arg-parsing or bench-matching in this library, so you can't run cargo bench . Instead, the user needs to put different benches into functions, and add/remove those functions from bench main. The reason for this is that those libraries are heavy-weight and would likely require some macros to select which benches to run which decreases readability and understandability.
Examples
Getting a hint of what parts of your application take time
"I have this iterator, and I'd like to get some sense of how long it takes to complete"
use Duration;
use Timeable;
"I have this loop that has side effects, and I'd like to time its execution"
use run_timed_from_iterator;
More involved comparisons
"My algorithm is pretty stupid, but I'm only sorting vectors with a max-length of 5, so maybe it doesn't matter in the grand scheme of things"
use BenchmarkConfig;
"I'd like to compare different implementations with each other"
use black_box;
Contribution
We welcome community contributions to this project.
Please read our Contributor Guide for more information on how to get started. Please also read our Contributor Terms before you make any contributions.
Any contribution intentionally submitted for inclusion in an Embark Studios project, shall comply with the Rust standard licensing model (MIT OR Apache 2.0) and therefore be dual licensed as described below, without any additional terms or conditions:
License
This contribution is dual licensed under EITHER OF
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
For clarity, "your" refers to Embark or any other licensee/user of the contribution.